//
//  LevelManager.cpp
//  BoxupPuzzle
//
//  Created by Nguyen Van Tien on 8/24/13.
//
//

#include "LevelManager.h"
#include "LevelData.h"
//#include "CCFileUtils.h"
#include "CCFileUtilsWin32.h"
#include <vector>

using namespace cocos2d;
using namespace std;

LevelManager* LevelManager::GetInstance()
{
    static LevelManager* instance = NULL;
    if (!instance)
        instance = new LevelManager;
    return instance;
}

LevelManager::LevelManager()
{
    m_LevelList = CCArray::create();
    m_LevelList->retain();
}

LevelManager::~LevelManager()
{
    m_LevelList->removeAllObjects();
    m_LevelList->release();
}

void LevelManager::LoadLevel()
{
    //const char* path = cocos2d::CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("level1").c_str();
	vector <string> paths;
	paths.push_back("resource");
	//CCFileUtils::sharedFileUtils()->setSearchPaths(paths);
	//const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(("level1", "resource");
    //const char* path = "E:\\Cocos2D_Project\\project\\BoxUpPuzzle\\BoxUpPuzzle\\BoxUpPuzzle\\Resources\\level1.bin";
	const char* path = "e:\\research\\cocos2d\\project\\upload\\BoxUpPuzzle\\BoxUpPuzzle\\Resources\\level1.bin";
    FILE *fp = fopen(path, "rb");
    
    if (fp == NULL)
        return;
    
    LevelData* pLevel = LevelData::CreateInstance();
    pLevel->Deserialize(fp);
    m_LevelList->addObject(pLevel);
}

LevelData* LevelManager::GetLevel(int iLevelIndex)
{
    if (iLevelIndex >= m_LevelList->count())
        return NULL;
    return (LevelData*) m_LevelList->objectAtIndex(iLevelIndex);
}